﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using objetos;
using database;
using System.Data;

namespace dados
{
    public class DAL_TABLE
    {
  
        public List<String> Campos(String tabela)
        {

            DAO_DATABASE db = new DAO_DATABASE();
            DataSet ds = new DataSet();         
            List<string> lista = new List<string>();
            StringBuilder sb = new StringBuilder();
            sb.Append("SELECT TABLE_NAME, ORDINAL_POSITION, ");
            sb.Append(" COLUMN_NAME, DATA_TYPE, IS_NULLABLE ");
            sb.Append(" FROM INFORMATION_SCHEMA.COLUMNS");
            sb.Append(" WHERE TABLE_NAME = @tabela");
            db.CreateParameter("@tabela", SqlDbType.VarChar, tabela);
            ds = db.ExecuteQuery(sb.ToString());
             

            if (!db.DataSetIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {                                  
                    lista.Add(dr["COLUMN_NAME"].ToString());
                }


            }
            return lista;

        }

        public List<string> Tabelas()
        {
            DAO_DATABASE db = new DAO_DATABASE();

            List<string> lista = new List<string>();
            DataSet ds = new DataSet();
            ds = db.ExecuteQuery("  SELECT name as tabela FROM sys.tables WHERE name like 'tb%'  order by name");
            if (!db.DataSetIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    lista.Add(dr["tabela"].ToString());
                }

            }
            return lista;

        }


    }
}
